//
//  ReversiInitializeController.m
//  Reversi
//
//  Created by 成瀬 龍人 on 2/9/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ReversiInitializeController.h"
#import "ReversiVirtualPlayers.h"

@implementation ReversiInitializeController
- (id)init{
	self->selectedItemIndex = 0;
	return self;
}

- (IBAction)close:(id)sender{
	ReversiVirtualPlayers* customDataSource = (ReversiVirtualPlayers*)[playerComboBox dataSource];
	id player = [customDataSource createPlayerObjectAtIndex:[playerComboBox indexOfSelectedItem]];
	[reversiController initReversi:nil:player];
	[initializePanel orderOut:self];
	[[NSApplication sharedApplication]
	 endSheet:initializePanel];
}

- (IBAction)selectItem:(id)sender{
	selectedItemIndex = [playerComboBox indexOfSelectedItem];
	ReversiVirtualPlayers* customDataSource = (ReversiVirtualPlayers*)[playerComboBox dataSource];
	[descriptionField setStringValue:[customDataSource descriptionAtIndex:selectedItemIndex]];
}

- (void)windowDidBecomeKey:(NSNotification *)notification{
	ReversiVirtualPlayers* customDataSource = (ReversiVirtualPlayers*)[playerComboBox dataSource];
	[customDataSource loadPlugIns];
	[playerComboBox reloadData];
	[playerComboBox selectItemAtIndex:selectedItemIndex];
	[playerComboBox performClick:self];
}
@end
